﻿@model Vizzio.Models.Pedido

@{
    ViewBag.Title = "Editar Pedido";
    var Productos = ViewBag.productos as List<Vizzio.Models.ProductoDePedido>;
}

<h2>Editar Pedido</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Pedido</h4>
        <hr />
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.PedidoID)

        <div class="form-group">
            @Html.LabelFor(model => model.ClienteID, "ClienteID", new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("ClienteID", String.Empty)
                @Html.ValidationMessageFor(model => model.ClienteID)
            </div>
        </div>

        @*<div class="form-group">
            @Html.LabelFor(model => model.ProductoID, "ProductoID", new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("ProductoID", String.Empty)
                @Html.ValidationMessageFor(model => model.ProductoID)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Cantidad, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Cantidad)
                @Html.ValidationMessageFor(model => model.Cantidad)
            </div>
        </div>*@

        @*<div class="form-group">
            @Html.LabelFor(model => model.Fecha, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Fecha)
                @Html.ValidationMessageFor(model => model.Fecha)
            </div>
        </div>*@
        <div class="form-group">
            @Html.LabelFor(model => model.Fecha, "* Fecha de Pedido", new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span><input type="text" name="Fecha" class="form-control" readonly value="@DateTime.Now.Date.ToShortDateString()">
                </div>
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.CostoTotal, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.CostoTotal)
                @Html.ValidationMessageFor(model => model.CostoTotal)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Modificar" class="btn btn-default" />
            </div>
        </div>
    </div>
    <p> Lista de Productos </p>

    <table class=" table table-striped table-hover ">
        <tr>
            <th>
                @Html.DisplayName("Nombre")
            </th>
            <th>
                @Html.DisplayName("Empresa")
            </th>
            <th>
                @Html.DisplayName("Presentacion")
            </th>
            <th>
                @Html.DisplayName("Cantidad")
            </th>
            <th>
                @Html.DisplayName("Costo")
            </th>
            <th></th>
        </tr>

        @foreach (var item in Productos)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Nombre)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Empresa)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Presentacion)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Cantidad)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Costo)
                </td>
                <td>
                    @Html.ActionLink("Eliminar", "DeleteProduct", new { pid = item.productoID, ppid = ViewBag.pedidoID })
                </td>

            </tr>
        }

    </table>
}

<div>
    @Html.ActionLink("Lista de Pedidos", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")


    <script type="text/javascript">
    var listaDeProductos;
    var contador_productos = 0;
    var aux = new Date();
    var fechaActual = aux.getDay + "-" + aux.getMonth + "-" + aux.getFullYear;
    var fechaMaxima = aux;
    fechaMaxima.setMonth(aux.getMonth() + 12);
    $(document).ready(function () {
        $('.input-group.date').datepicker({
            format: "dd/mm/yyyy",
            weekStart: 1,
            startDate: fechaActual,
            endDate: fechaMaxima,
            todayBtn: "linked",
            language: "es",
            autoclose: true,
            todayHighlight: true
        });
        })
      </script>
 }
